//document.write("in test<br>");
function test2() {
    stack = new Array();
    alert(stack);
    stack.push(2);
    stack.pop();
    alert(stack);
}

function test() {
	var testCase = new JavaOperatorExecute(3,4,2);
	//testCase.iconst_(3);
	testCase.showStack();
	//testCase.iadd();
}

function JavaOperatorExecute(Stack,Locals,Args_size) {
	this.stackNum = 0;   //input varibles, perhaps be changed. This is according to the javap results
	this.variableNum = 0;
	this.argsSize = 0;
	this.operandStack; //operand stack array
	this.variables; //variable array
	
 	var init=function() {
		alert("init function");
		this.stackNum = Stack;
		this.variableNum = Locals;
		this.argsSize = Args_size;
		this.operandStack= new Array();
		this.variables = new Array();
	}
	
	this.showStack = function() {
		alert("in show");
		alert(this.operandStack);
	}
	
	init();
}


//iadd: iadd
JavaOperatorExecute.prototype.iadd = function() {
	if(this.operandStack.length > 2) {
		this.operandStack.push(this.operandStack.pop() + this.operandStack.pop());
	} else {
		//*exception: 2 pop in the array with <=2 elements
	}
}

//iconst_<n>: iconst_1, should be converted into iconst_(1)
JavaOperatorExecute.prototype.iconst_ = function(num) {
	//alert("i_const");
	//alert(num);
	//alert(this.operandStack);
	this.operandStack.push(num);
	//alert(this.operandStack);
}

//iload_<n>: iload_(n)
JavaOperatorExecute.prototype.iload_ = function(index) {
	this.operandStack.push(this.variables[index]);
}

//imul: imul, multiply two top stack numbers then push it back
JavaOperatorExecute.prototype.imul = function() {
	if(this.operandStack.length > 2) {
		this.operandStack.push(this.operandStack.pop() * this.operandStack.pop());
	} else {
		//*exception: 2 pop in the array with <=2 elements
	}
}

//istore_<n>: istore_(n)
JavaOperatorExecute.prototype.istore_ = function(index) {
	if(this.operandStack.length > 0) {
		this.variables[index] = this.operandStack.pop();
	} else {
		//*exception: pop while stack is empty
	}
}

//istore n: istore(n)
JavaOperatorExecute.prototype.istore = function(index) {
	if(this.operandStack.length > 0) {
		this.variables[index] = this.operandStack.pop();
	} else {
		//*exception: pop while stack is empty
	}
}




function test1() {
	alert("test!!!");
	var stack = new Array();
	stack[1] = 'xiaogou';
	stack[2] = 45;
	alert(stack.toString());
	for(var x in stack) {
		alert(stack[x]);
	}
}
